
function p1() {
  return new Promise((deal, reject) => {
    setTimeout(() => {
      deal('p1')
    }, 2000)
  })
}

function p2() {
  return new Promise((resolve, reject) => {
    setTimeout(() => {
      resolve('p2')
    }, 2000)
  })
}
const start = Date.now()

// promise then 中的回调执行会以第一个为标准，要打断 promise链 可以 return 一个
// 新的 promise
p1()
  .then(() => {
    console.log('time:', Date.now() - start)
  })
  .then(() => {
    console.log('time:', Date.now() - start)
    return p2()
  })
  .then(() => {
    console.log('time:', Date.now() - start)
  })

const start1 = Date.now();

(async function fn2() {
  await p2()
  await p2()
  console.log('time1:', Date.now() - start1)
})()

function add(a, b) {
  let pos = 0
  let res = ''

  while (a.lengtsh > pos || b.length > pos) {
    var carry = res.length - pos++
    res = (~~a[a.length - pos] + ~~b[b.length - pos] + carry) + res.substring(carry)
  }

  console.log(res)
}

add('999', '26661')

